package com.zmn.oms.common.utils;

import com.zmn.common.utils.date.DateUtil;

import java.util.Date;

/**
 * @author ：SongWeidong
 * @date ：2020/6/11 16:09
 * @description：时间转换
 */
public class TimeUtils {

    // 秒 转时分秒
    public static String getDate(int date) {
        String s = "00";
        String m = "00";
        String h = "00";
        if (date < 60) {
            s = String.valueOf(date);
        } else if (date > 60 && date < 3600) {
            m = String.valueOf(date / 60);
            s = String.valueOf(date % 60);
        } else {
            h = String.valueOf(date / 3600);
            m = String.valueOf((date % 3600) / 60);
            s = String.valueOf((date % 3600) % 60);
        }
        return unitFormat(Integer.parseInt(h)) + ":" + unitFormat(Integer.parseInt(m)) + ":" + unitFormat(Integer.parseInt(s));
    }

    private static String unitFormat(int i) {
        String retStr ;
        if (i >= 0 && i < 10) {
            retStr = "0" + i;
        }
        else {
            retStr = "" + i;
        }
        return retStr;
    }

    /**
     * 是否在当前日期到指定日期的时间范围内
     * @param date 时间
     * @param days 天数
     * @return
     */
    public static boolean isCurDateRange(Date date, Integer days) {
        if (date == null || days == null) {
            return false;
        }

        Integer intDay = Integer.valueOf(DateUtil.toString(date, DateUtil.FORMAT_DATE2));
        Date curDate = new Date();
        Integer intToday = Integer.valueOf(DateUtil.toString(curDate, DateUtil.FORMAT_DATE2));
        Integer intAfter14Day = Integer.valueOf(DateUtil.toString(DateUtil.addDays(curDate, days), DateUtil.FORMAT_DATE2));
        if (intDay >= intToday && intDay <= intAfter14Day) {
            return true;
        } else {
            return false;
        }
    }

}
